<template>
	<view class="ys">
		<view class="navlist">
			<view :class="isActive == item.type ?'nav_item active':'nav_item'" v-for="(item,index) in navlist"
				:key="index" @click="changeNav(item.type)">
				{{item.text}}
			</view>
		</view>
		<view class="list" v-if="list.length != 0">
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="top">
					<image :src="item.voucher_url | getImg" @click="seeImg(item.voucher_url)" mode="aspectFill">
					</image>
					<view class="info">
						<view class="name">
							账号 : {{item.username}}
						</view>
						<view class="phone">
							充值金额 : {{item.num}}
						</view>
						<view class="phone">
							手机号 : {{item.phone}}
						</view>
						<view class="phone status">
							状态 : <text>{{item.status_name}}</text>
						</view>
					</view>
					<view class="btns" v-if="item.status == 0">
						<button @click="change(item,1)">通过</button>
						<button class="red" @click="change(item,2)">驳回</button>
					</view>
				</view>
			</view>
		</view>
		<view class="no-list" v-else>
			- 暂无数据 -
		</view>
	</view>
</template>

<script>
	import {
		DianRecharge,
		RechargeStatus
	} from "@/api/shop.js"
	export default {
		data() {
			return {
				list: [],
				page: 1,
				last_page: 1,
				isActive: 5,
				navlist: [{
						text: '全部',
						type: '5'
					},
					{
						text: '待审核',
						type: '0'
					},
					{
						text: '已通过',
						type: '1'
					},
					{
						text: '已驳回',
						type: '2'
					}
				],
			}
		},
		onLoad(e) {
			this.DianRecharge()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.DianRecharge()
			}
		},
		methods: {
			seeImg(url) {
				uni.previewImage({
					urls: [this.$config.websiteUrl + url]
				})
			},
			changeNav(index) {
				this.isActive = index
				this.page = 1
				this.last_page = 1
				this.list = []
				this.DianRecharge()
			},
			change(item, type) {
				RechargeStatus({
					id: item.id,
					status: type
				}).then(res => {
					uni.$showMsg(res.message)
					if (res.status == 1) {
						item.status = type
						this.page = 1
						this.last_page = 1
						this.list = []
						this.DianRecharge()
					}
				})
			},
			DianRecharge() {
				DianRecharge({
					page: this.page,
					status: this.isActive
				}).then(res => {
					if (res.status == 1) {
						this.list = this.list.concat(res.data.data)
						this.last_page = res.data.last_page
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.navlist {
		display: flex;
		justify-content: space-between;
		position: sticky;
		top: 0;
		/* #ifdef H5 */
		top: 44px;
		/* #endif */
		width: 100%;
		max-width: 500px;
		z-index: 999;
		background: #6b7490;

		.nav_item {
			width: 25%;
			text-align: center;
			color: #ffffff80;
			height: 40px;
			justify-content: center;
			// line-height: 50px;
			font-weight: bold;
			display: flex;
			flex-direction: column;
			font-size: 14px;
		}

		.active {
			color: #fff;
			position: relative;
		}

		.active::after {
			position: absolute;
			content: '';
			width: 25px;
			height: 3px;
			background: #fff;
			left: 50%;
			bottom: 4px;
			transform: translate(-50%);
		}
	}

	.list {
		padding: 10px;

		.item {
			padding: 10px;
			border-radius: 5px;
			box-sizing: border-box;
			background: #fff;
			margin-bottom: 10px;

			.top {
				display: flex;
				align-items: center;
			}

			image {
				width: 80px;
				height: 80px;
				margin-right: 10px;
			}

			.info {
				flex: 1;
				box-sizing: border-box;

				.name {
					font-size: 14px;
					margin-bottom: 3px;
					font-weight: bold;
				}

				.phone {
					font-size: 12px;
					color: #777;
					margin-bottom: 3px;
				}

				.status {
					text {
						color: #069cff;
						font-weight: bold;
						margin-left: 5px;
					}
				}
			}

			.btns {
				button {
					width: 70px;
					height: 30px;
					margin-bottom: 10px;
					line-height: 30px;
					font-size: 13px;
					background: #E1ECFE;
					color: #6b7490;
					font-weight: bold;
				}

				.red {
					background: #cb0000;
					color: #fff;
				}
			}

		}
	}
</style>